package thread_pool;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Created with IDEA
 * author:ju bai
 * Date:2021/5/23
 * Time:11:11
 * shutdown/shutdownNow区别
 **/
public class PoolDemo19 {
    public static void main(String[] args) {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(
                10,10,0, TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(1000)
        );
        for (int i = 0; i < 100; i++) {
            int finalI = i;
            executor.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println(String.format("编号：%d,线程名：%s",
                            finalI,Thread.currentThread().getName()));
                }
            });
        }
        //拒绝执行新任务，等待线程池中的任务执行完停止线程池
        executor.shutdown();
        //不会等待任务队列中的任务执行完成停止线程池
        executor.shutdownNow();
    }
}
